package shape;
import java.util.ArrayList;

import processing.core.PVector;


public class PlaneEquation {

	
	float A;
	float B;
	float C;
	float D;
	
	public PlaneEquation(float a, float b, float c, float d) {
		A = a;
		B = b;
		C = c;
		D = d;
	}
	
	public float f(PVector x){
		return A*x.x + B*x.y + C*x.z + D;
	}
	public int f(PolyhedraFace x) throws Exception{
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;
		
		
		for(int i=0; i < x.size(); i++){
			int newEval = (f(x.getVertex(i))>0)?1:((f(x.getVertex(i))<0)?-1:0);
			if(newEval>max) max = newEval;
			if(newEval<min) min = newEval;
		}
		if(max==0 && min ==0) {throw new Exception("Same plane");}
		return (Math.abs(max-min)>1)?0:((max+min>0)?1:-1);
	}

	public float getD() {
		return D;
	}
}
